/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.install.util;

import cn.com.ksplatform.install.model.InstallInfo;
import cn.com.ksplatform.install.service.DBType;

public class DbHelp {
	/**
	 * 生成Url
	 * @param info
	 */
	public static void setUrl(InstallInfo info){
		String dataBaseType = info.getDataBaseType();
		if(dataBaseType.equals(DBType.MySql.getValue())){
			String url = "jdbc:mysql://"+info.getDataBaseHost()+":"+info.getDataBasePort()+"/"+info.getDataBaseName()+"?characterEncoding=utf-8";
			info.setDataBaseUrl(url);
			info.hibernateProperties =  "hibernate.dialect=org.hibernate.dialect.MySQL5Dialect";
		}else if(dataBaseType.equals(DBType.Oracle.getValue())){
			String url = "jdbc:oracle:thin:@"+info.getDataBaseHost()+":"+info.getDataBasePort()+":"+info.getDataBaseName();
			info.setDataBaseUrl(url);
			info.hibernateProperties = "hibernate.dialect=org.hibernate.dialect.Oracle10gDialect";
		}else if(dataBaseType.equals(DBType.SqlServer.getValue())){
			 String url="jdbc:sqlserver://"+info.getDataBaseHost()+":"+info.getDataBasePort()+";database="+info.getDataBaseName()+";user="+info.getDataBaseUserName()+";password="+info.getDataBasePassWord();
			 info.setDataBaseUrl(url);
			 info.hibernateProperties = "hibernate.dialect=org.hibernate.dialect.SQLServerDialect";
		}else if(dataBaseType.equals(DBType.HSQLDB.getValue())){
			String url = "jdbc:hsqldb:hsql://localhost:" + info.getDataBasePort() + "/" + info.getDataBaseName();
			info.hibernateProperties = "hibernate.dialect=org.hibernate.dialect.HSQLDialect";
			info.setDataBaseUrl(url);
		}
	}
}
